package com.thz.system.manager;

import com.thz.common.core.constants.CacheConstants;
import com.thz.redis.utlis.RedisUtil;
import com.thz.system.pojo.exam.Exam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @Author thz
 * @Date 2025/3/25
 */
@Component
public class ExamCacheManager {

    @Autowired
    private RedisUtil redisUtil;

    public void addCache(Exam exam) {
        redisUtil.leftPushForList(getExamListKey(), exam.getExamId());
        String examKey = getDetailKey(exam.getExamId());
        redisUtil.setCacheObject(examKey, exam);
    }

    public void deleteCache(Long examId) {
        redisUtil.removeForList(getExamListKey(), examId);
        String examKey = getDetailKey(examId);
        redisUtil.deleteObject(examKey);
        redisUtil.deleteObject(getExamQuestionListKey(examId));
    }

    private String getExamListKey() {
        return CacheConstants.EXAM_UNFINISHED_LIST;
    }

    private String getDetailKey(Long examId) {
        return CacheConstants.EXAM_DETAIL + examId;
    }

    private String getExamQuestionListKey(Long examId) {
        return CacheConstants.EXAM_QUESTION_LIST + examId;
    }

}
